package from;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.util.lang.Bytes;

import java.io.File;

public class FileUploadPage extends WebPage {
    public FileUploadPage(){
        super();
        final FileUploadField fileUploadField = new FileUploadField("imageUpload");

        Form form = new Form("form"){
            protected void onSubmit(){
             final FileUpload upload = fileUploadField.getFileUpload();
                if (upload != null) {
                    try{
                        upload.writeTo(new File("D:\\1.txt"));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                super.onSubmit();
            }
        };
        form.add(fileUploadField);

        form.setMultiPart(true);//设置文件可上传
        form.setMaxSize(Bytes.kilobytes(1000));
    }
}
